//
//  WEXStatusToolBar.swift
//  microBlog
//
//  Created by apple on 16/4/20.
//  Copyright © 2016年 Hill. All rights reserved.
//

import UIKit

class WEXStatusToolBar: UIView {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        
        //添加按钮
        let retweetBtn = addChildButton("转发", imgName: "timeline_icon_retweet")
        let commentBtn = addChildButton("评论", imgName: "timeline_icon_comment")
        let unlikeBtn = addChildButton("赞", imgName: "timeline_icon_unlike")
        
        let sp1 = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        let sp2 = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        addSubview(sp1);addSubview(sp2)
        
        // 设置转发按钮
        retweetBtn.snp_makeConstraints { (make) -> Void in
            
            make.top.leading.bottom.equalTo(self)
            make.width.equalTo(commentBtn)
            
        }
        // 设置评论按钮
        commentBtn.snp_makeConstraints { (make) -> Void in
            
            make.centerY.equalTo(retweetBtn)
            make.leading.equalTo(retweetBtn.snp_trailing)
            make.trailing.equalTo(unlikeBtn.snp_leading)
            make.width.equalTo(unlikeBtn)
            
        }
        
        // 设置点赞按钮
        unlikeBtn.snp_makeConstraints { (make) -> Void in
            
            make.top.trailing.bottom.equalTo(self)
            make.width.equalTo(retweetBtn)
            
        }
        
        // 分割线
        sp1.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(retweetBtn.snp_trailing)
            make.centerY.equalTo(self)
        }
        
        sp2.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(commentBtn.snp_trailing)
            make.centerY.equalTo(self)
        }

        
        
    }
    
    
    // MARK: - 加载按钮
    private func addChildButton(title: String, imgName: String) -> UIButton {
        
        let button = UIButton(textColor: UIColor.darkGrayColor(), textFont: toolBarButtonFont)
        
        button.setTitle(title, forState: UIControlState.Normal)
        // 设置显示的图片
        button.setImage(UIImage(named: imgName), forState: UIControlState.Normal)
        // 设置不同状态的下的背景图片
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        addSubview(button)
        
        return button
        
    }
    
    
    
}
